<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class About_model extends CI_Model
{
	
	public function __construct()
	{
		parent::__construct();

	}
	function users_getall($userid)
	{
	   
		/*$users = $this->db->get('users',$userid);
	    return $users->result();*/
	}
	
	function hobbies_getall()
	{
	    $hobbies = $this->db->get('hobbies');
	    return $hobbies->result();
	}
	
	function user_hobbies_insert($insert)
	{
		
				foreach($insert as $hobbies)			
				{
				$this->db->insert('user_hobbies',$hobbies);
				}
				
	}
	
	function education_insert($insert)
	{
		
	$get_id = $this->db->get_where('education',array('user_id'=>$this->input->post('users')))->result();
		
		if(count($get_id)==0)
					{	
		foreach($insert as $education)
		{
					$this->db->insert('education',$education);
		}}else{	
		foreach($insert as $update)
		{
			$this->db->update('education',array('institute'=>$update['institute'],'degree'=>$update['degree'],'started'=>$update['started'],'ended'=>$update['ended']),array('user_id'=>$update['user_id'],'institute'=>$update['institute']));
			
		}}
		
	}

	function language_insert($insert,$users)
	{
		
	$get_id = $this->db->get_where('language',array('user_id'=>$this->input->post('users')))->result();
		
		if(count($get_id)==0)
					{	
		foreach($insert as $language)
		{
					$language['user_id']=$users;
					$this->db->insert('language',$language);
		}}else{	
		foreach($insert as $update)
		{
			$language['user_id']=$users;
			$this->db->update('language',$language);
			
		}}
		
	}

	function address_insert($insert)
	{
	$get_id = $this->db->get_where('address',array('user_id'=>$this->input->post('users')))->result();
		if(count($get_id)==0)
					{	
					$this->db->insert('address',$insert);
		}else{	
	
			$this->db->update('address',array('country'=>$insert['country'],'state'=>$insert['state'],'city'=>$insert['city'],'street'=>$insert['street'],'zipcode'=>$insert['zipcode']),array('user_id'=>$insert['user_id']));
			
		}
		
	}
	
	function phone_update($update,$users)
	{
		
		$this->db->update('users',array('phone'=>$update),array('id'=>$users));
	}
	
	function user_update($update,$users)
	{
		
		$this->db->update('users',array('username'=>$update),array('id'=>$users));
	}
	
	function designationbyid($id)
	{
		$this->db->select('users_groups.*,user_type.*');
    	$this->db->from('user_type');
    	$this->db->join('users_groups', 'user_type_id = user_type.id');
		$this->db->where('users_groups.user_id =',$id);
		$designationbyid = $this->db->get();
		return $designationbyid->result();
	}
	public function get_user_details($id)
	{
		$this->db->select('users.*,users_groups.*');
		$this->db->from('users');
		$this->db->where('users.id = '.$id);
		$this->db->join('users_groups','users.id = users_groups.user_id');
		return $this->db->get()->row_array();
	}
	function userdetails($id)
	{
		$this->db->select('users.*');
    	$this->db->from('users');
    	$this->db->where('users.id =',$id);
		$userdetails = $this->db->get();
		return $userdetails->result();
	}
	
	function get_address_by_userid($id)
	{
		$this->db->select('address.*');
    	$this->db->from('address');
    	$this->db->where('user_id =',$id);
		$address = $this->db->get();
		return $address->result();
	}
	function get_education_by_userid($id)
	{
		$this->db->select('education.*');
    	$this->db->from('education');
    	$this->db->where('user_id =',$id);
		$education = $this->db->get();
		return $education->result();
	}
	function get_language_by_userid($id)
	{
		$this->db->select('language.*');
    	$this->db->from('language');
    	$this->db->where('user_id =',$id);
		$language = $this->db->get();
		return $language->result();
	}
	function skillsimage($id)
	{
		$this->db->select('skills_custom.*,skills.*');
    	$this->db->from('skills');
    	$this->db->join('skills_custom', 'skills_id = skills.id');
		$this->db->where('skills_custom.user_id =',$id);
		$skillsimage = $this->db->get();
		return $skillsimage->result();
	}
	function skillschart($id)
	{
		$this->db->select('skills_custom.name,skills_custom.level');
    	$this->db->from('users');
    	$this->db->join('skills_custom', 'user_id = users.id');
		$this->db->where('skills_custom.user_id =',$id);
		$skillschart = $this->db->get();
		return $skillschart->result();
	}
	
	function efficiencychart($id)
	{
		$this->db->select('efficiency_custom.name,efficiency_custom.level');
    	$this->db->from('users');
    	$this->db->join('efficiency_custom', 'user_id = users.id');
		$this->db->where('efficiency_custom.user_id =',$id);
		$efficiencychart = $this->db->get();
		return $efficiencychart->result();
        
	}
	function hobbyimage($id)
	{
		$this->db->select('user_hobbies.*,hobbies.*');
    	$this->db->from('hobbies');
    	$this->db->join('user_hobbies', 'hobbies_id = hobbies.id');
		$this->db->where('user_hobbies.user_id =',$id);
		$hobbyimage = $this->db->get();
		return $hobbyimage->result();
	}
	function toolschart($id)
	{
		$this->db->select('tools_custom.name,tools_custom.level');
    	$this->db->from('users');
    	$this->db->join('tools_custom', 'user_id = users.id');
		$this->db->where('tools_custom.user_id =',$id);
		$toolschart = $this->db->get();
		return $toolschart->result();
	}
	function coffeebyid($id)
	{
		$this->db->select('coffee.*');
    	$this->db->from('users');
    	$this->db->join('coffee', 'user_id = users.id');
		$this->db->where('coffee.user_id =',$id);
		$coffeebyid = $this->db->get();
		return $coffeebyid->result();
	}
	function efficiencyfields($id)
	{
		$this->db->select('efficiency_custom.*,');
    	$this->db->from('users');
    	$this->db->join('efficiency_custom', 'user_id = users.id');
		$this->db->where('efficiency_custom.user_id =',$id);
		$efficiencyfields = $this->db->get();
		return $efficiencyfields->result_array();
      
	}

	


}
